//
//  BiFileManager.m
//  XinBanEducation
//
//  Created by ChenBin on 14-5-13.
//  Copyright (c) 2014年 Nahan Cop. All rights reserved.
//

#import "BiFileManager.h"

#define kDefaultDBName @"data.db"

@implementation BiFileManager

+ (NSString*)getAbsoluteDBFilePath
{
	NSString *absolutePath = [[BiFileManager dbRootPath] stringByAppendingString:[NSString stringWithFormat:@"/%@", kDefaultDBName]];
    return absolutePath;
}

+ (NSString*)dbRootPath
{
    NSString * dbRootPath = [[BiFileManager docPath] stringByAppendingString:@"/db"];
    BOOL isDir;
    if (![[NSFileManager defaultManager] fileExistsAtPath:dbRootPath isDirectory:&isDir])
    {
        [[NSFileManager defaultManager] createDirectoryAtPath:dbRootPath withIntermediateDirectories:YES attributes:nil error:nil];
    }
    
    return dbRootPath;
}
+ (NSString*)htmlRootPath
{
    NSString * rootPath = [[NSBundle mainBundle] resourcePath];
    NSString * htmlRootPath = [NSString stringWithFormat:@"%@/resource/html", rootPath];
    
    return htmlRootPath;
}
+ (NSString*)imageRootPath
{
    NSString * rootPath = [[BiFileManager docPath] stringByAppendingString:@"/image"];
    
    BOOL isDir;
    if (![[NSFileManager defaultManager] fileExistsAtPath:rootPath isDirectory:&isDir])
    {
        [[NSFileManager defaultManager] createDirectoryAtPath:rootPath withIntermediateDirectories:YES attributes:nil error:nil];
    }
    
    return rootPath;
}
+ (NSString*)getTmpFilePath
{
    return [NSString stringWithFormat:@"%@/deviceToken.txt", [self docPath]];
}

+ (NSString*)docPath
{
    // 沙盒Docu目录
    NSString * docPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
    
    return docPath;
}

@end
